<?php

class BackendController extends Controller
{
    public $hederMainLinks=array();
    public static $hederMainLinksArray=array(
        array(
            'id'=>'',
            'class'=>'',
            'link'=>'admin/index',
            'name'=>'Главная',
        ),
        array(
            'id'=>'',
            'class'=>'',
            'link'=>'admin/articles',
            'name'=>'Articles',
        ),
        array(
            'id'=>'',
            'class'=>'',
            'link'=>'admin/files',
            'name'=>'Files',
        ),
        array(
            'id'=>'',
            'class'=>'',
            'link'=>'admin/profile',
            'name'=>'Profile',
        ),
        array(
            'id'=>'',
            'class'=>'',
            'link'=>'admin/settings',
            'name'=>'Settings',
        ),
        array(
            'id'=>'',
            'class'=>'',
            'link'=>'admin/user/management',
            'name'=>'Пользователи',
        ),
    );

    public $subnavLinks=array();
    public static $subnavLinksArray=array(
        array(
            'link'=>'admin/link1',
            'name'=>'Подменю 1',
        ),
        array(
            'link'=>'admin/link2',
            'name'=>'Подменю 2',
        ),
        array(
            'link'=>'admin/link3',
            'name'=>'Подменю 3',
        ),
        array(
            'link'=>'admin/link4',
            'name'=>'Подменю 4',
        ),
        array(
            'link'=>'admin/link5',
            'name'=>'Подменю 5',
        ),
    );

    public $dashboardIcons=array();
    public static $dashboardIconsArray=array(
        array(
            'class'=>'',
            'link'=>'admin/article',
            'alt'=>'write',
            'img'=>'/images/Crystal_Clear_write.gif',
            'name'=>'New article',
        ),
        array(
            'class'=>'',
            'link'=>'admin/uploadFile',
            'alt'=>'upload',
            'img'=>'/images/Crystal_Clear_file.gif',
            'name'=>'Upload file',
        ),
        array(
            'class'=>'',
            'link'=>'admin/articles',
            'alt'=>'articles',
            'img'=>'/images/Crystal_Clear_files.gif',
            'name'=>'Articles',
        ),
        array(
            'class'=>'',
            'link'=>'admin/calendar',
            'alt'=>'calendar',
            'img'=>'/images/Crystal_Clear_calendar.gif',
            'name'=>'Calendar',
        ),
        array(
            'class'=>'',
            'link'=>'admin/profile',
            'alt'=>'profile',
            'img'=>'/images/Crystal_Clear_user.gif',
            'name'=>'My profile',
        ),
        array(
            'class'=>'',
            'link'=>'admin/stats',
            'alt'=>'stats',
            'img'=>'/images/Crystal_Clear_stats.gif',
            'name'=>'Stats',
        ),
        array(
            'class'=>'',
            'link'=>'admin/settings',
            'alt'=>'settings',
            'img'=>'/images/Crystal_Clear_settings.gif',
            'name'=>'Настройки',
        ),
        array(
            'class'=>'',
            'link'=>'admin/user/management',
            'alt'=>'users',
            'img'=>'/images/Crystal_Clear_users.gif',
            'name'=>'Пользователи',
        ),
    );

    public $categoryImage;

    public function init()
    {
        Yii::app()->theme='backend/default';
        if(!Yii::app()->user->checkAccess('admin') && !Yii::app()->user->checkAccess('moderator')) $this->redirect(Yii::app()->createUrl('user/auth/login'));
        $currentRoute=Yii::app()->request->requestUri;
        foreach(self::$hederMainLinksArray as $array){
            if('/'.$array['link']==$currentRoute) $array['id']=' id="current"';
            $array['link']=Yii::app()->createAbsoluteUrl($array['link']);
            $this->hederMainLinks[]=(object)$array;
        }
        foreach(self::$subnavLinksArray as $array){
            $array['link']=Yii::app()->createAbsoluteUrl($array['link']);
            $this->subnavLinks[]=(object)$array;
        }
    }

    public function filters()
    {
        return array(
            'accessControl',
        );
    }

    public function accessRules()
    {
        return array(
            array(
                'allow',
                'roles'=>array('admin'),
            ),
            array(
                'deny',
                'users'=>array('*'),
            ),
        );
    }
}